data  segment
	array	dw  12,11,22,33,44,55,66,77,88,99,111,222,223
	number	dw  55
	low_idx dw	?
	high_idx dw	?
	string1 db "No Match!$"
	string2 db "Match: $"
data  ends

code segment
main proc far
	assume cs:code,ds:data,es:data

start:
	push ds
	sub ax,ax
	push ax

	mov ax,data
	mov ds,ax
	mov es,ax

	lea di,array
	mov ax,[number]
	
	cmp ax,[di+2]
	ja chk_last
	lea si,[di+2]
	jmp match
	
chk_last:
	mov si,[di]
	shl si,1
	add si,di
	cmp ax,[si]
	jb search
	jmp match

search:
	mov low_idx,1
	mov bx,[di]
	mov high_idx,bx
	mov bx,di

mid:	mov cx,low_idx
	mov dx,high_idx
	cmp cx,dx
	ja no_match
	add cx,dx
	shr cx,1
	mov si,cx
	shl si,1

compare:
	cmp ax,[bx+si]
	je match
	ja higher
	dec cx
	mov high_idx,cx
	jmp mid

higher:
	inc cx
	mov low_idx,cx
	jmp mid

no_match:
	lea dx,string1
	mov ah,9h
	int 21h
	jmp exit

match:
	lea dx,string2
	mov ah,9h
	int 21h
	shr si,1
	mov dx,si
	add dx,30h
	mov ah,2h
	int 21h
exit: 	
	ret
main endp
code ends
	end start
;注意：lea dx,string1与mov dx,string1意义完全不同
